package com.ibeifeng.crm.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;

import com.ibeifeng.crm.bean.ClassInfo;

import com.ibeifeng.crm.dao.ClassInfoDao;



@Repository
public class ClassInfoDaoImpl implements ClassInfoDao {
	Logger log = Logger.getLogger(ClassInfoDaoImpl.class);
	
	@Resource
	SqlSessionFactory factory;
	@Override
	public int add(ClassInfo classInfo) {
		int result = factory.openSession().insert("com.ibeifeng.crm.bean.mapping.ClassInfoNS.insert", classInfo);
		return result;
	}
	@Override
	public int update(ClassInfo classInfo) {
		int result = factory.openSession().update("com.ibeifeng.crm.bean.mapping.ClassInfoNS.update", classInfo);
		return result;
	}
	@Override
	public int delete(int [] idsdel) {
		int result = factory.openSession().delete("com.ibeifeng.crm.bean.mapping.ClassInfoNS.delete", idsdel);
		return result;
	}
	@Override
	public ClassInfo queryClassInfo(ClassInfo classInfo) {
		ClassInfo ci = factory.openSession().selectOne("com.ibeifeng.crm.bean.mapping.ClassInfoNS.findById", classInfo);
		return ci;
	}
	
	
	
	Map map = new HashMap();

	@Override
	public List<ClassInfo> findAllSplit(int page, int pageSize, String column,
			String keyWord) {
		int start = (page-1)*pageSize;
		map.put("start", start);
		map.put("pageSize", pageSize);
		map.put("column", column);
		map.put("keyWord", keyWord);
		List<ClassInfo> list = factory.openSession().selectList("com.ibeifeng.crm.bean.mapping.ClassInfoNS.findAllSplit",map);
		return list;
	}
	
	@Override
	public int count() {
		int count = factory.openSession().selectOne("com.ibeifeng.crm.bean.mapping.ClassInfoNS.getAllCount",map);
		return count;
	}
	
	@Override
	public List<ClassInfo> queryMethod() {
		List<ClassInfo> classinfos = factory.openSession().selectList("com.ibeifeng.crm.bean.mapping.ClassInfoNS.getClassInfos");
		return classinfos;
	}
	
	@Override
	public ClassInfo queryOne(int id) {
		ClassInfo classinfo = factory.openSession().selectOne("com.ibeifeng.crm.bean.mapping.ClassInfoNS.queryOne",id);
		return classinfo;
	}
	
	

}
